#ifndef PIPE_PREPAR_H
#define PIPE_PREPAR_H

#include "drm_drv/drm_plane_drv.h"
#include "v4l2_drv/v4l2_capture.h"
#include <unistd.h>

enum Pipe_Prepar_State{
    pm_init,
    pm_runing,
    pm_stoping,
    pm_stoped
};


void format_convert(char *databuff, int datalen);
void Flip_image(unsigned char *srcbuff, unsigned char *dstbuff, int datalen);

class Pipe_Prepar {

private:
    struct drm_plane *plane=NULL;
    Capture *cap0=NULL;
     Pipe_Prepar_State status=pm_init;
     std::mutex status_mutex;
     std::mutex mode_mutex;
     std::thread *pipeThread;

     void prepar_thread_run();
     void prepar_inf_thread_run();
     void prepar_wg_thread_run();

public:
        bool gRedColorSwitch = true;

        Pipe_Prepar_State get_status(void){
            Pipe_Prepar_State tmp;
            status_mutex.lock();
            tmp=status;
            status_mutex.unlock();
            return tmp;
        }
        void start(Capture *cap0,struct drm_plane *plane);
        void re_run(){
            status_mutex.lock();
            if(status==pm_stoped){
                status=pm_runing;
            }
            status_mutex.unlock();
        }
        void set_status(Pipe_Prepar_State tmp){
            status_mutex.lock();
            status=tmp;
            status_mutex.unlock();
        }
        void wait_stoping(void){
            while(get_status()!=pm_stoped){
                usleep(100);
            }
        }
        void stop(){
            if(get_status()==pm_runing){
                set_status(pm_stoping);
                wait_stoping();
            }
        }

    };

#endif // prepar_H

